
function doAjax(config)
  {
	$('.message').hide();
  	var ajaxResult;
  	jQuery.ajax({
			url: config.url,
			data:config.data,
			type:config.type,
			async: true,
			dataType: config.dataType,
			complete:config.complete,
			error:config.error,
			success:config.success
		});
  }
 
 function getAjaxResul(config)
 {
 	
 
 	jQuery.ajax({
			url: config.url,
			data:config.data,
			type:config.type,
			async: true,
			dataType: config.dataType,
			success:config.callback,
			error:config.callback
		});
 	
 	
 
 }
 function showTooltip(tiptext,obj)
 {
	 alert($obj.prop('href'));
 }
 
 $(function () {
	 
	 

	 	 $.fn.mytip = function()
		    {
		    };
		    
		    $('.mytip').mytip();
		
		
     
	    $.fn.serializeObject = function()
	    {
	       var o = {};
	       var a = this.serializeArray();
	       $.each(a, function() {
	           if (o[this.name]) {
	               if (!o[this.name].push) {
	                   o[this.name] = [o[this.name]];
	               }
	               o[this.name].push(this.value || '');
	           } else {
	               o[this.name] = this.value || '';
	           }
	       });
	       return o;
	    };
	      
	    $.fn.window = function(config)
	    {
	    	var _config={footerButtons:[],headerButtons:[],title:"No Title is Defined."};
	    	
	    	/* merge object2 into object1 */
	    	$.extend(_config, config);
	    	
	    	
	      $contain=this;
	      $contain.addClass("ui-window demo ui-widget ui-window-content ui-corner-top");
		     // $contain.append($titleBar);
		     // $contain.height('500');
	      $titleBar=$("<div class='ui-window-titlebar ui-window-header ui-corner-top ui-helper-clearfix'></div>");
	      $titleBar.prependTo($contain);
	      $title=$("<span class='ui-dialog-title'>"+_config.title+"</span>");
	      $title.appendTo($titleBar);
	      if(_config.headerButtons.length>0){
	    	  
		      $toolbarPane=$('<div class="ui-dialog-titlebar-buttonpane" style="position: absolute; top: 50%; right: 0.3em; margin-top: -10px; height: 18px;"></div>');
		      jQuery.each(_config.headerButtons, function(i, val) {
		      $button=$('<a class="title-toolbar ui-corner-all" role="button" style="position: static; top: auto; right: auto; margin: 0px;"></a>');
		      $button.bind("click",val.onClick);
		      $buttonCss=$('<span class="toolbar-icon">close</span>');
		      $buttonCss.addClass(val.css);
		      $buttonCss.appendTo($button);
		      $button.appendTo($toolbarPane);
		     
		   
	       });
	      $toolbarPane.appendTo($titleBar)
	    }
	      if(_config.footerButtons.length>0){
	      $footer=$('<div class="window-footer"></div>');
	      $footer.css('height','35px');
	      $footer.css('position','relative');
	      $footer.css('bottom',0);
	     // $footerTitle=$('<span class="ui-dialog-title"> footer</span>');
	      //$footerTitle.appendTo($footer);
	      $footerToolbarPane=$('<div></div>');
	      jQuery.each(_config.footerButtons, function(i, val) {
	    	  $button = $('<button class=""><span>'+val.name+'</span></button>');
	    	  $button.addClass(val.css).bind("click",val.onClick);
	    	  
	    	  $footerToolbarPane.append($button);
	       });
	      //$footerToolbarPane.append('<button class=""><span style="padding:10px">submit</span></button>');
	      //$footerToolbarPane.append('<button class=""><span style="padding:10px">submit</span></button>');
	      //$footerToolbarPane.append( $footerTitle);
	      $footer.append($footerToolbarPane);
	      $footer.appendTo($contain);
	      }
	    };
	    
	    function _complete(result)
	    {
	    	//alert("_complete");
	    }

	    function _success(result)
	    {
	    	alert(result);
	    	
	    }

	    function _error(result)
	    {
	    	alert("_error"+result);
	    }
	});

 $(document).ready(function() {
	 
	 $(".mainmenu .parent").click(function() {
	     	
         alert('hello');
         $(".mainmenu a").next('.sub-menu').slideDown();
         return false;
        
     });
	 
     $(".dropdown img.flag").addClass("flagvisibility");

     $(".dropdown dt a").click(function() {
     	
         $(".dropdown dd ul").toggle();
        
     });
                 
      $(".dropdown dd ul li a").click(function() {
         var text = $(this).html();
         $(".dropdown dt a span").html(text);
         $(".dropdown dd ul").hide();
         
     }); 
                 
    

     $(document).bind('click', function(e) {
         var $clicked = $(e.target);
         if (! $clicked.parents().hasClass("dropdown"))
             $(".dropdown dd ul").hide();
     });


    
 });
 
 function _Complete(result)
 {
 	//alert("_complete");
 }

 function _success(result)
 {
 	alert(result);
 	
 }

 function _error(result)
 {
	 alert("_error"+result);
 }
 
 function buildGrid(gridId, gridData, gridColumns, gridOption)
 {
	 var minWidth=20;
	 var rowClass=[];
	 rowClass[0]="#FFFFFF";
	 rowClass[1]="#F2F2F2";
	 var $table =$('<table cellspacing="0" cellpadding="0" style="border-collapse:collpase;"></table');
	 var $headerTr=$('<tr class="grid-header-row"></tr>');
	 for(i=0;i< gridColumns.length;i++)
		 //var headerRow=$('<div class="grid-header-row"></div>');
		 {
		 $('<td class="grid-cell">'+gridColumns[i].name+'</td>').appendTo($headerTr);
		 }
	 $headerTr.appendTo($table);
	 for(i=0;i< gridData.length;i++)
	 {
	  var $divRow = $('<tr class="grid-data-row"  data-index="'+i+'"></tr>');
	  	
	  	 for(k=0;k< gridColumns.length;k++)
		 //var headerRow=$('<div class="grid-header-row"></div>');
		 {
		 $('<td class="grid-cell">'+gridData[i][gridColumns[k].id]+'</td>').appendTo($divRow);
		 }
	 	
	
	 $divRow.appendTo($table);
	 }
	$table.appendTo( $(gridId));
	$table.on("click", ".grid-data-row", function(event){
		alert(gridData[$(this).attr('data-index')]);
	});
	$table.on("hover", ".grid-data-row", function(event){
		$(this).toggleClass('tr-hover');
	});
	
	 
	// return _grid;
	    
	 
 }
 /* Global method to build the grid in the application. this method will take some paramter to build the grid.
  * GridId- hold the ID of holder for the Grid in String format.
  * GridData- Will come as pure json object of data which are going to be populated in the grid.
  * GridColumn- will come as JSON data holding the column detail like name, id, datatype etc.
  * GridOption- JSON format holding the grid configuration details.
  */
 function CustomGrid(GridId, GridData, GridColumns, GridOption)
 {
	
	 	
	 editableGrid = new EditableGrid("DemoGridJsData");
	 editableGrid.load({"metadata": GridColumns, "data": GridData});
	 editableGrid.renderGrid(GridId, "testgrid");
	 return editableGrid;
	
	    
	 
 }
 
 function registerForDragDrop(config)
 {

 	config.grid.onDragInit.subscribe(function (e, dd) {
         // prevent the grid from cancelling drag'n'drop by defaultell
     	//alert('h');
         e.stopImmediatePropagation();
       });
 	
 	config.grid.onDragStart.subscribe(function (e, dd) {
         var cell = config.grid.getCellFromEvent(e);
         if (!cell) {
           return;
         }

         dd.row = cell.row;
         if (!config.data[dd.row]) {
           return;
         }

         if (Slick.GlobalEditorLock.isActive()) {
           return;
         }

         e.stopImmediatePropagation();
         dd.mode = config.mode;
         dd.action=config.action;

         var selectedRows = config.grid.getSelectedRows();

         if (!selectedRows.length || $.inArray(dd.row, selectedRows) == -1) {
           selectedRows = [dd.row];
           config.grid.setSelectedRows(selectedRows);
         }

         dd.rows = selectedRows;
         dd.count = selectedRows.length;
         var rowsToDelete = dd.rows.sort().reverse();
         var dataToPass=[];
         for (var i = 0; i < rowsToDelete.length; i++) {
         
 		  dataToPass.push(config.data[rowsToDelete[i]]);
         }
         
         dd.data=dataToPass;

         var proxy = $("<span></span>")
             .css({
               position: "absolute",
               display: "inline-block",
               padding: "4px 10px",
               background: "#e0e0e0",
               border: "1px solid gray",
               "z-index": 99999,
               "-moz-border-radius": "8px",
               "-moz-box-shadow": "2px 2px 6px silver"
             })
             .text("Drag to Menu to add " + dd.count + " selected row(s)")
             .appendTo("body");

         dd.helper = proxy;

         $(".delete-area").css("background", "pink");

         return proxy;
       });
        
 	config.grid.onDrag.subscribe(function (e, dd) {
            if (dd.mode != "recycle") {
              return;
            }
            e.stopImmediatePropagation();
            dd.helper.css({top: e.pageY + 5, left: e.pageX + 5});
          });
 	config.grid.onDragEnd.subscribe(function (e, dd) {
            if (dd.mode != "recycle") {
              return;
            }
            e.stopImmediatePropagation();
            dd.helper.remove();
            $(".delete-area").css("background", "beige");
            alert(dd.action);
          });
 
	 
 }
 
 function comparer(a, b) {
	  var x = a[sortcol], y = b[sortcol];
	  return (x == y ? 0 : (x > y ? 1 : -1));
	}
 
 /*method will load the content from the particular url to sub screen provided as paramter NOTE:method is working and usefull, do not remove*/
 function _loadContent(url, windowContent)
 {
	 
	
		
		 $("#"+windowContent).load(url);
		 
	

 }